import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Library {
    List<book> list;
    static Scanner in;

    void Show() {
        for (int i = 0; i < list.size(); i++) {
            System.out.print(i + 1 + ": " + list.get(i).getName() + " " + list.get(i).getAuthor() + " 状态: ");
            if (list.get(i).isBorrowed())
                System.out.println("已借出");
            else System.out.println("可借");
        }


    }

    boolean BorrowBook(book b) {
        if (b.isBorrowed()) {
            return false;
        }
        b.setBorrowed(true);
        b.setLendTime(7);
        return true;
    }

    void Repay(Person p) {
        p.ShowLend();
        System.out.println("请输入你要还的图书编号或输入 0 退出");
        int t = in.nextInt();
        do {
            if (t == 0) {
                return;
            }
            if (t < 0 || t > p.getList().size()) {
                Main.Err();
                t = in.nextInt();
            }
        } while (t < 0 || t > p.getList().size());
        p.getList().remove(p.getList().get(t - 1));
        System.out.println("还书成功！返回主菜单");
    }

    void Lend(Person p) {
        Show();
        System.out.println("输入你要借书的编号或者输入 0 退出");
        int t = in.nextInt();
        do {
            if (t == 0) {
                return;
            }
            if (t < 0 || t > list.size()) {
                Main.Err();
                t = in.nextInt();
            }
        } while (t < 0 || t > list.size());
        if (list.get(t - 1).isBorrowed()) {
            System.out.println("借阅失败，该书已借出");
        } else {
            list.get(t - 1).setBorrowed(true);
            list.get(t - 1).setLendTime(7);
            System.out.println("借阅成功!");
            p.getList().add(list.get(t - 1));
        }
    }

    book Find(book b) {
        return list.get(list.indexOf(b));
    }

    public Library() {
        list = new ArrayList<book>();
        in = new Scanner(System.in);
    }

    public void add(book b) {
        list.add(b);
    }
}
